package com.ktwlsoft.fundmanage.domain.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 资金进出记录
 *
 * @author Name on 2019/8/20 10:57
 * @version 1.0
 */
@ApiModel("资金进出记录-FundInRecordRepository")
@Entity
@Getter
@Setter
public class FundInRecord extends BaseFundRecord {
    /**
     * 入账时间，真实转账时间
     */
    @ApiModelProperty("入账时间")
    @Column(columnDefinition = "datetime DEFAULT NULL COMMENT '入账时间'")
    private Date payTime;

    /**
     * 缴款流水号
     */
    @ApiModelProperty("缴款流水号")
    @Column(columnDefinition = "varchar(30) DEFAULT NULL COMMENT '缴款流水号'")
    private String payFlowCode;

    /**
     * 缴款标志
     */
    @ApiModelProperty("缴款标志")
    @Column(columnDefinition = "varchar(30) DEFAULT NULL COMMENT '缴款标志'")
    private String payFlag;

    /**
     * 入账对账:true.已对账,false.未对账
     */
    @ApiModelProperty("入账对账:true.已对账,false.未对账")
    @Column(columnDefinition = "bit DEFAULT 0 COMMENT '入账对账:true.已对账,false.未对账'")
    private boolean payCheck = false;

    /**
     * 入账对账人id
     */
    @ApiModelProperty("入账对账人id")
    @Column(columnDefinition = "varchar(50) DEFAULT NULL COMMENT '入账对账人id'")
    private String payCheckerId;

    /**
     * 入账对账人姓名
     */
    @ApiModelProperty("入账对账人姓名")
    @Column(columnDefinition = "varchar(50) DEFAULT NULL COMMENT '入账对账人姓名'")
    private String payChecker;

    /**
     * 入账对账时间
     */
    @ApiModelProperty("入账对账时间")
    @Column(columnDefinition = "datetime DEFAULT NULL COMMENT '对账时间'")
    private Date payCheckTime;

    /**
     * 缴款人姓名, 即买方
     */
    @ApiModelProperty("缴款人姓名")
    @Column(columnDefinition = "varchar(100) DEFAULT NULL COMMENT '缴款人姓名'")
    @Size(max = 100, message = "缴款人姓名参数超长")
    private String payer;

    @ApiModelProperty("交款人的Id")
    @Column(columnDefinition = "varchar(30) DEFAULT NULL COMMENT '交款人id'")
    private String payerId;

    /**
     * 付款银行
     */
    @ApiModelProperty("付款银行")
    @Column(columnDefinition = "varchar(200) DEFAULT NULL COMMENT '付款银行'")
    @Size(max = 200, message = "转入银行参数超长")
    private String payBank;

    /**
     * 付款账号
     */
    @ApiModelProperty("付款账号")
    @Column(columnDefinition = "varchar(50) DEFAULT NULL COMMENT '付款账号'")
    private String payAccount;

    /**
     * 取消对账人
     */
    @ApiModelProperty("取消对账人")
    @Column(columnDefinition = "varchar(20) DEFAULT NULL COMMENT '取消对账操作的人'")
    private String cancelName;

    /**
     * 取消对账人Id
     */
    @ApiModelProperty("取消对账人Id")
    @Column(columnDefinition = "varchar(100) DEFAULT NULL COMMENT '取消对账操作的人的id'")
    private String cancelId;

    /**
     * 取消对账时间
     */
    @ApiModelProperty("取消对账时间")
    @Column(columnDefinition = "datetime DEFAULT NULL COMMENT '取消对账时间'")
    private Date cancelDate;

    /**
     * 已被划拨
     */
    @ApiModelProperty("已被划拨")
    @Column(columnDefinition = "decimal(16,8) DEFAULT 0 COMMENT '已被划拨(万元)'")
    private BigDecimal hasTransfer = BigDecimal.ZERO;

    /**
     * 是否划拨
     */
    @ApiModelProperty("是否划拨")
    @Column(columnDefinition = "bit DEFAULT 0 COMMENT '是否划拨'")
    private boolean transferd = false;

    @ApiModelProperty("收款账户")
    @Column(columnDefinition = "varchar(30) default null comment '收款账户'")
    private String receiverAccount;

    @ApiModelProperty("收款银行")
    @Column(columnDefinition = "varchar(30) default null comment '收款银行'")
    private String receiverBank;

    @ApiModelProperty("取消原因")
    private String cancelReson;

    @ApiModelProperty("买方姓名")
    @Transient
    private String buyerName;

    @ApiModelProperty("买方证件号")
    @Transient
    private String buyerCertificateNumber;

    @ApiModelProperty("卖方姓名")
    @Transient
    private String sellerName;

    @ApiModelProperty("卖方证件号")
    @Transient
    private String sellerCertificateNumber;

    @ApiModelProperty("所有权证号")
    @Transient
    private String ownershipNo;

    @ApiModelProperty("划款单类型")
    @Transient
    private String transferType;

    @ApiModelProperty("开具人")
    @Transient
    private String operator;

    @ApiModelProperty("开具人")
    @Transient
    private String operatorId;

    public void restore(BigDecimal hasTransfer){
        this.hasTransfer = this.hasTransfer.subtract(hasTransfer);
        this.transferd = false;
    }

//    public void cancelHandle(){
//        this.setDnCode(0L);
//    }
}